package springframework.bean;

import com.qumoyugo.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author Cedric
 * @date 2021/12/10 09:43
 * @description 字符串转日期
 */
public class StringToLocalDateConverter implements Converter<String, LocalDate> {

    private DateTimeFormatter DATE_TIME_FORMATTER;

    public StringToLocalDateConverter(String pattern) {
        this.DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(pattern);
    }

    @Override
    public LocalDate convert(String source) {
        return LocalDate.parse(source, DATE_TIME_FORMATTER);
    }
}
